package com.hzt.agprosaleplatform.mapper;

import com.hzt.agprosaleplatform.entity.FinanceApplication;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;

@Mapper
public interface FinanceApplicationMapper {

    @Insert("INSERT INTO t_finance_application (user_id, shop_id, goods_id, amount, purpose, term, interestRate, status, applyTime, audit_time, audit_opinion) " +
            "VALUES (#{userId}, #{shopId}, #{goodsId}, #{amount}, #{purpose}, #{term}, #{interestRate}, #{status}, #{applyTime}, #{auditTime}, #{auditOpinion})")
    @Options(useGeneratedKeys = true, keyProperty = "financeId")
    int insert(FinanceApplication application);

    @Select("SELECT * FROM t_finance_application WHERE finance_id = #{financeId}")
    FinanceApplication selectById(Integer financeId);

    @Select("SELECT * FROM t_finance_application WHERE user_id = #{userId}")
    List<FinanceApplication> selectByUserId(String userId);

    @Select("SELECT * FROM t_finance_application WHERE status = #{status}")
    List<FinanceApplication> selectByStatus(Integer status);

    @Update("UPDATE t_finance_application SET status = #{status}, audit_time = #{auditTime}, audit_opinion = #{auditOpinion} WHERE finance_id = #{financeId}")
    int updateStatus(@Param("financeId") Integer financeId, @Param("status") Integer status,
                     @Param("auditTime") Date auditTime, @Param("auditOpinion") String auditOpinion);

}
